const express = require("express");
const router = require("./router");
const mongoose = require("mongoose");
const utils = require("./common/utils");
const cors = require( 'cors' );
const app = express();
const port = 3001;

app.use(cors());
utils.init();
const mongoDB = "mongodb://127.0.0.1/lottery";
// const mongoDB = "mongodb://172.21.0.17:27017/lottery";

mongoose.connect(mongoDB);
mongoose.Promise = global.Promise;
const db = mongoose.connection;
db.on("error", console.error.bind(console, "MongoDB 连接错误："));

app.use(express.json());
app.use('/v1/api', express.static('public'));
app.use('/img', express.static('img'));
app.use(router);

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`);
});
